package com.huatai.bi.utils;

import com.huawei.shade.com.cloud.sdk.ServiceException;

/**
 * @BelongsProject: itc-airport-cloud
 * @BelongsPackage: com.huatai.bi.utils
 * @Author: hecaiy
 * @CreateTime: 2024-07-23  20:16
 * @Description: TODO
 * @Version: 1.0
 */
public class StringBuildUtil {


	/**
	 * 操作特殊字符
	 * @param str
	 * @return
	 */
	public static void originalFilenameTS(String str) {
		StringBuilder sb = new StringBuilder();
		for (char a:str.toCharArray()){
			if(!Character.isLetterOrDigit(a) && a!=' ' && a!='_'){
				sb.append(a);
			}
		}
		if(sb.length()>0){
			throw new ServiceException("列名称不允许有特殊字符，特殊字符为"+sb.toString());
		}
	}

	/**
	 * 操作特殊字符
	 * @param str
	 * @return
	 */
	public static StringBuilder originalFilename(String str) {
		StringBuilder sb = new StringBuilder();
		for (char a:str.toCharArray()){
			if(!Character.isLetterOrDigit(a) && a!=' ' && a!='_'){
				sb.append(a);
			}
		}
		return sb;
	}

	/**
	 * 去除最后一个逗号
	 *
	 * @param sb
	 */
	public static void deleteSBWithSpace(StringBuilder sb, String replace,int length) {
		if (sb.length() > 0) {
			//删除字符串
			if(length>1){
				int index = sb.lastIndexOf(replace);
				if (index != -1) {
					sb.delete(index, index + length);
				}
			}else {
				sb.deleteCharAt(sb.lastIndexOf(replace));
			}
		}
	}
}
